function data = generateSimData(params,calibrateParams,orderApp,selectY,numSim)

% The setdiff implies that we do not overwrite elements in params based on calibrateparams
selectParams = fieldnames(params);
namesCalibrate = setdiff(fieldnames(calibrateParams),selectParams);
for i=1:size(namesCalibrate,1)
   name = namesCalibrate(i);  
   params.(name{1}) = calibrateParams.(name{1}); 
end

% Solving the model
[model,errorMes] = perturbationDSGEmodel(params,orderApp,selectY);

% Simulate the economy
randn('seed',10);   % Please do not change the seed
ne      = size(model.eta,2);
shocks  = randn(ne,numSim);
[ySim,xf_sim,xs_sim,xrd_sim] = simulate_3rd_kron_v2(model.gx,model.gxx,model.gxxx,...
    model.hx,model.hxx,model.hxxx,model.gss,model.gssx,model.gsss,model.hss,model.hssx,model.hsss,...
    model.eta,shocks,orderApp);

% Adding the steady state level for the controls
y  = ySim + repmat(model.g0,1,numSim);
% For output: T * ny
data = y';



end

